package com.loopy.fruns.dao.impl;

import com.loopy.fruns.dao.BasicDAO;
import com.loopy.fruns.dao.OrderItemDAO;
import com.loopy.fruns.entity.OrderItem;

import java.util.List;

public class OrderItemDAOImpl extends BasicDAO<OrderItem> implements OrderItemDAO {
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "insert into `orderItem`(`id`,`name` ,`price`,`count`,`total_price`,`order_id`) values(?,?,?,?,?,?)";
        return update(sql,orderItem.getId(), orderItem.getName(), orderItem.getPrice(), orderItem.getCount(), orderItem.getTotalPrice(), orderItem.getOrderId());
    }

    @Override
    public List<OrderItem> getOrderItemListByOrderId(String orderId) {
        String sql="select `id`,`name`,`price`,`count`,`total_price`as totalPrice from `orderitem` where `order_id`=?";
        List<OrderItem> orderItemList = Multi(sql, OrderItem.class, orderId);
        return orderItemList;
    }
}
